package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.Activity;
import com.zutassociation.system.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/3/18 17:30
 */

@RestController
@RequestMapping("/activity")
public class ActivityController extends BaseController {

    @Autowired
    private ActivityService activityService;


    /**
     * 获取活动列表
     */
//    @PreAuthorize("@ss.hasPermi('system:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(Activity activity) {
        startPage();
        List<Activity> list = activityService.selectActivityList(activity);
        return getDataTable(list);
    }

    /**
     * 获取活动列表
     */
//    @PreAuthorize("@ss.hasPermi('system:activity:list')")
    @GetMapping("/listClick")
    public TableDataInfo listClick(Activity activity) {
        startPage();
        List<Activity> list = activityService.selectActivityListClick(activity);
        return getDataTable(list);
    }

    /**
     * 根据活动编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:activity:query')")
    @GetMapping(value = "getUpActivity/{activityId}")
    public AjaxResult getUpActivity(@PathVariable("activityId") Long activityId) {
        return AjaxResult.success(activityService.selectUpActivity(activityId));
    }

//    @PreAuthorize("@ss.hasPermi('system:activity:query')")
    @GetMapping(value = "getNextActivity/{activityId}")
    public AjaxResult getNextActivity(@PathVariable("activityId") Long activityId) {
        return AjaxResult.success(activityService.selectNextActivity(activityId));
    }

//    @PreAuthorize("@ss.hasPermi('system:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId) {
        return AjaxResult.success(activityService.selectActivityById(activityId));
    }

    /**
     * 新增活动
     */
    @PreAuthorize("@ss.hasPermi('system:activity:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Activity activity) {
        activity.setCreateBy(SecurityUtils.getUsername());
        return toAjax(activityService.insertActivity(activity));
    }

    /**
     * 修改活动
     */
    @PreAuthorize("@ss.hasPermi('system:activity:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Activity activity) {
        activity.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(activityService.updateActivity(activity));
    }

//    @PreAuthorize("@ss.hasPermi('system:activity:edit')")
    @PutMapping("/updateActivityClick")
    public AjaxResult updateActivityClick(@Validated @RequestBody Activity activity) {
        return toAjax(activityService.updateActivityClick(activity));
    }

    /**
     * 删除活动
     */
    @PreAuthorize("@ss.hasPermi('system:activity:remove')")
    @DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds) {
        return toAjax(activityService.deleteActivityByIds(activityIds));
    }

}
